/*
	Copyright (c) 2007, ANYwebcam.com Pty Ltd. All rights reserved.

	The software in this package is published under the terms of the BSD style 
	license, a copy of which has been included with this distribution in the 
	license.txt file.
*/
package com.anywebcam.di.component
{
	import com.anywebcam.di.*;
	
	/**
	 * Caches instances of a child DIComponent's implementation
	 * <p>Useful for simulating singleton access to class instance</p>
	 */
	public class CachingComponent extends DecoratingComponent
	{
		private var _instance:Object; 
		
		/**
		 * Constructor
		 * 
		 * @param delegate The DIComponent to cache
		 */
		public function CachingComponent( delegate:DIComponent )
		{
			super( delegate );
		}
		
		/**
		 * @inheritDoc
		 */
		override public function getInstance( container:DIContainer ):Object
		{
			if( _instance == null )
			{
				_instance = super.getInstance( container );
			}
			return _instance;
		}
	}
}